package Test.Test02;

import java.util.Arrays;

/**
 * @Author: kirito
 * @Date: 2024/5/6 21:03
 * @Description:
 */

public class Test04 {
    static boolean[][] visited;
    public static void main(String[] args) {
        int[][] grid = {{1, 1, 1},
                        {1, 1, 0},
                        {1, 0, 1},
                        {1, 1, 1}};
        int m = grid.length;
        int n = grid[0].length;

        visited = new boolean[m][n];

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] == 0 && !visited[i][j]) {
                    dfs(grid, i, j);
                }

            }
        }
        for (int[] arr : grid) {
            System.out.println(Arrays.toString(arr));
        }
    }

    private static void dfs(int[][] grid, int row, int col) {
        if (row < 0
        || row >= grid.length
        || col < 0
        || col >= grid[0].length) {
            return;
        }
        for (int i = 0; i < grid[0].length; i++) {
            grid[row][i] = 0;
            visited[row][i] = true;
        }
        for (int i = 0; i < grid.length; i++) {
            grid[i][col] = 0;
            visited[i][col] = true;
        }

        
    }
}
